﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NGourd.Core.Reports
{
    public class ReportNode
    {
        public ReportNode(ReportTarget targetType, string text)
        {
            TargetType = targetType;
            Text = text;
            Nodes = new List<ReportNode>();
        }

        private ReportStatus status = ReportStatus.UNKNOWN;

        public ReportTarget TargetType
        {
            get;
            private set;
        }

        public ReportStatus Status
        {
            get
            {
                return status;
            }
            set
            {
                status = value;
            }
        }

        public void UpdateStatus()
        {
            foreach (var node in Nodes)
            {
                node.UpdateStatus();
                if ((int)node.Status > (int)status)
                    status = node.Status;
            }
        }

        public IList<ReportNode> Nodes
        {
            get;
            private set;
        }

        public string Text
        {
            get;
            private set;
        }

        public override string ToString()
        {
            return String.Format("{0}: {1} [{2}]", TargetType, Text, Status);
        }

        public void Accept(IReportNodeVisitor visitor)
        {
            visitor.Visit(this);
        }
    }
    
}
